'use strict';

import { Application } from 'egg'

const apiHeader = '/api/user'
const apiAuthHeader = '/auth/user'
const apiSuperAuthHeader = '/super-auth/user'

const getApi = (path: string) => {
  return `${apiHeader}/${path}`
}

const getAuthApi = (path: string) => {
  return `${apiAuthHeader}/${path}`
}

const getSuperAuthApi = (path: string) => {
  return `${apiSuperAuthHeader}/${path}`
}

export default (app: Application) => {
  const { router, controller } = app;

  router.post(getApi('reset-pass'), controller.user.resetPass);
  router.post(getApi('login'), controller.user.login);
  router.get(getAuthApi('session-login'), controller.user.sessionLogin);

  router.get(getAuthApi('logut'), controller.user.logut);
  // 修改当前账户密码
  router.post(getAuthApi('update-password'), controller.user.updatePassword);
  // 获取当前定账号下面的项目列表
  router.get(getAuthApi('project-list'), controller.user.projectList);

  router.get(apiSuperAuthHeader, controller.user.index);
  router.post(apiSuperAuthHeader, controller.user.create);
  router.post(getSuperAuthApi('update-enabled'), controller.user.userEnabled);
  router.delete(apiSuperAuthHeader, controller.user.destroy);
  router.post(getSuperAuthApi('update-user-password'), controller.user.changeOtherPassword);
  router.post(getSuperAuthApi('add-project/:id'), controller.user.addProject);
  router.delete(getSuperAuthApi('remove-project/:id'), controller.user.removeProject);
};
